/**
 * Created by Administrator on 2017/8/1.
 */

angular.module('WfbPlatformApp')
  .factory('transactionService', ['$http', '$q', function ($http, $q) {

    return {

      getPoint: function (paramData) {
        var deferred = $q.defer();
        $http({
          method: 'POST',
          url: 'transaction/getPoint',
          data: paramData
        }).then(function success(result) {
            if (result.data.retCode == '1') {
              // 请求成功
              deferred.resolve(result.data);
            }
          },
          function error(error) {
            deferred.reject(error);//请求失败
          }
        );
        return deferred.promise;//返回承诺
      },

      invest: function (paramData) {
        var deferred = $q.defer();
        $http({
          method: 'POST',
          url: 'transaction/invest',
          data: paramData
        }).then(function success(result) {
            if (result.data.retCode == '1') {
              // 请求成功
              deferred.resolve(result.data);
            }
          },
          function error(error) {
            deferred.reject(error);//请求失败
          }
        );
        return deferred.promise;//返回承诺
      },

      getPoints: function (paramData) {
        var deferred = $q.defer();
        $http({
          method: 'POST',
          url: 'transaction/getPoints',
          data: paramData
        }).then(function success(result) {
            if (result.data.retCode == '1') {
              // 请求成功
              deferred.resolve(result.data);
            }
          },
          function error(error) {
            deferred.reject(error);//请求失败
          }
        );
        return deferred.promise;//返回承诺
      },

      getProfitPoints: function (paramData) {
        var deferred = $q.defer();
        $http({
          method: 'POST',
          url: 'transaction/getProfitPoints',
          data: paramData
        }).then(function success(result) {
            if (result.data.retCode == '1') {
              // 请求成功
              deferred.resolve(result.data);
            }
          },
          function error(error) {
            deferred.reject(error);//请求失败
          }
        );
        return deferred.promise;//返回承诺
      },

      getFinished: function (paramData) {
        var deferred = $q.defer();
        $http({
          method: 'POST',
          url: 'transaction/getFinished',
          data: paramData
        }).then(function success(result) {
            if (result.data.retCode == '1') {
              // 请求成功
              deferred.resolve(result.data);
            }
          },
          function error(error) {
            deferred.reject(error);//请求失败
          }
        );
        return deferred.promise;//返回承诺
      },

      getRunning: function (paramData) {
        var deferred = $q.defer();
        $http({
          method: 'POST',
          url: 'transaction/getRunning',
          data: paramData
        }).then(function success(result) {
            if (result.data.retCode == '1') {
              // 请求成功
              deferred.resolve(result.data);
            }
          },
          function error(error) {
            deferred.reject(error);//请求失败
          }
        );
        return deferred.promise;//返回承诺
      },

      getWithdraws: function (paramData) {
        var deferred = $q.defer();
        $http({
          method: 'POST',
          url: 'transaction/getWithdraws',
          data: paramData
        }).then(function success(result) {
            if (result.data.retCode == '1') {
              // 请求成功
              deferred.resolve(result.data);
            }
          },
          function error(error) {
            deferred.reject(error);//请求失败
          }
        );
        return deferred.promise;//返回承诺
      },

      getTypes: function (paramData) {
        var deferred = $q.defer();
        $http({
          method: 'POST',
          url: 'transaction/getTypes',
          data: paramData
        }).then(function success(result) {
            if (result.data.retCode == '1') {
              // 请求成功
              deferred.resolve(result.data);
            }
          },
          function error(error) {
            deferred.reject(error);//请求失败
          }
        );
        return deferred.promise;//返回承诺
      },

      getWithdrawAddress: function (paramData) {
        var deferred = $q.defer();
        $http({
          method: 'POST',
          url: 'transaction/getAddrs',
          data: paramData
        }).then(function success(result) {
            if (result.data.retCode == '1') {
              // 请求成功
              deferred.resolve(result.data);
            }
          },
          function error(error) {
            deferred.reject(error);//请求失败
          }
        );
        return deferred.promise;//返回承诺
      },

      withdrawbind: function (paramData) {
        var deferred = $q.defer();
        $http({
          method: 'POST',
          url: 'transaction/withdrawbind',
          data: paramData
        }).then(function success(result) {
            if (result.data.retCode == '1') {
              // 请求成功
              deferred.resolve(result.data);
            }
          },
          function error(error) {
            deferred.reject(error);//请求失败
          }
        );
        return deferred.promise;//返回承诺
      },

      withdraw: function (paramData) {
        var deferred = $q.defer();
        $http({
          method: 'POST',
          url: 'transaction/withdraw',
          data: paramData
        }).then(function success(result) {
            if (result.data.retCode == '1') {
              // 请求成功
              deferred.resolve(result.data);
            }
          },
          function error(error) {
            deferred.reject(error);//请求失败
          }
        );
        return deferred.promise;//返回承诺
      },

      getTodayInterest: function (paramData) {
        var deferred = $q.defer();
        $http({
          method: 'POST',
          url: 'transaction/getTodayInterest',
          data: paramData
        }).then(function success(result) {
            if (result.data.retCode == '1') {
              // 请求成功
              deferred.resolve(result.data);
            }
          },
          function error(error) {
            deferred.reject(error);//请求失败
          }
        );
        return deferred.promise;//返回承诺
      },

      transPoint: function (paramData) {
        var deferred = $q.defer();
        $http({
          method: 'POST',
          url: 'transaction/transPoint',
          data: paramData
        }).then(function success(result) {
            if (result.data.retCode == '1') {
              // 请求成功
              deferred.resolve(result.data);
            }
          },
          function error(error) {
            deferred.reject(error);//请求失败
          }
        );
        return deferred.promise;//返回承诺
      },

      calculatePoint: function (paramData) {
        var deferred = $q.defer();
        $http({
          method: 'POST',
          url: 'transaction/calculatePoint',
          data: paramData
        }).then(function success(result) {
            if (result.data.retCode == '1') {
              // 请求成功
              deferred.resolve(result.data);
            }
          },
          function error(error) {
            deferred.reject(error);//请求失败
          }
        );
        return deferred.promise;//返回承诺
      },

      exchangePoint: function (paramData) {
        var deferred = $q.defer();
        $http({
          method: 'POST',
          url: 'transaction/exchangePoint',
          data: paramData
        }).then(function success(result) {
            if (result.data.retCode == '1') {
              // 请求成功
              deferred.resolve(result.data);
            }
          },
          function error(error) {
            deferred.reject(error);//请求失败
          }
        );
        return deferred.promise;//返回承诺
      },

      //获取收货地址
      getAddressList: function (paramData) {
        var deferred = $q.defer();
        $http({
          method: 'POST',
          url: 'addr/list',
          data: paramData
        }).then(function success(result) {
            if (result.data.retCode == '1') {
              // 请求成功
              deferred.resolve(result.data);
            }
          },
          function error(error) {
            deferred.reject(error);//请求失败
          }
        );
        return deferred.promise;//返回承诺
      },

      getOrderList: function (paramData) {
        var deferred = $q.defer();
        $http({
          method: 'POST',
          url: 'order/list',
          data: paramData
        }).then(function success(result) {
            if (result.data.retCode == '1') {
              // 请求成功
              deferred.resolve(result.data);
            }
          },
          function error(error) {
            deferred.reject(error);//请求失败
          }
        );
        return deferred.promise;//返回承诺
      },

    };
  }]);
